package coder812.common.utils;

import sun.misc.BASE64Encoder;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Created by 来自北海的风 on 2017/8/12.
 */
public class SecurityUtils {
    public static String encryPssword(String password)throws NoSuchAlgorithmException ,UnsupportedEncodingException{
        MessageDigest md5=MessageDigest.getInstance("MD5");
        BASE64Encoder base64Encoder=new BASE64Encoder();
        String result=base64Encoder.encode(md5.digest(password.getBytes("GBK")));
        return result;


    }
    public static boolean checkPassword(String inputPwd,String dbPwd) throws UnsupportedEncodingException, NoSuchAlgorithmException {
        String result=encryPssword(inputPwd);
        if(result.equals(dbPwd)){
            return true;
        }else {
            return false;
        }
    }
}
